<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Comment extends CI_Controller {

	public function __construct()
    {
        parent::__construct();
        $this->load->model('User_model');
        $this->load->model('Usernum_model');
        $this->load->model('Comment_model');
        $this->load->model('cert_model');
    }
	

	public function index($userid)
	{
		
		$this->load->service('user_service');
		$oUser = $this->user_service->get_user_homeinfo($userid, $this->loginID);
        
        $insid = $oUser['insid'];

        //如果此人是属于经纪公司的，此经纪公司是认证过的，则旗下所有的人都是认证过的
        if(!empty($insid)) {
            $userCert = $this->cert_model->get_by_id($insid);
            $ins_user = $this->User_model->get_info_by_id($insid);
        } else {
            //认证
            $userCert = $this->cert_model->get_by_id($userid);
        }

		$page     = _get_page();
		$pagesize = 10;
		$arrParam = array();
		$arrWhere = array('touserid'=>$userid,'status'=>1);		//条件

		$list = $this->Comment_model->fetch_page($page, $pagesize, $arrWhere);
// 		echo $this->Comment_model->db->last_query();die;
		
		if ($list && $list["rows"])
		{
			for ($i=0;$i<count($list["rows"]);$i++)
			{
				$comment = $this->Comment_model->fetch_row(array("id"=>$list["rows"][$i]["commentid"]),"skill,efficiency,attitude");
				$list["rows"][$i]["skill"] = $comment["skill"];
				$list["rows"][$i]["efficiency"] = $comment["efficiency"];
				$list["rows"][$i]["attitude"] = $comment["attitude"];
			}
		}

		//分页
		$pagecfg = array();
		$pagecfg['base_url']     = _create_url('i/comment/'.$userid, $arrParam);
		$pagecfg['total_rows']   = $list['count'];
		$pagecfg['cur_page'] = $page;
		$pagecfg['per_page'] = $pagesize;
		//$this->load->library('pagination');
		$this->pagination->initialize($pagecfg);
		$list['pages'] = $this->pagination->create_links();
		$list['page'] = $page;
		$list['pagesize'] = $pagesize;
		
		//用户类型、分类
		$userRole = '';
		if ($oUser['usertype'] == 1)
		{
			$userRole = $oUser['role']?$oUser['role']:'模特';
		}
		elseif ($oUser['usertype'] == 2)
		{
			$oSysType = _get_config('type');
			$oSysType = $oSysType[2];
			$oSysStr = '';
			foreach ($oSysType as $key => $v)
			{
				if(strpos(','.$oUser['type'].',',','.$key.',')>-1)
				{
					if ($oSysStr)
					{
						$oSysStr .= ','.$v;
					}
					else
					{
						$oSysStr = $v;
					}
				}
			}
			$userRole = $oSysStr?$oSysStr:'机构';
		}
		elseif ($oUser['usertype'] == 3)
		{
			$userRole = '公司';
		}
		elseif ($oUser['usertype'] == 4)
		{
			$userRole = $oUser['role']?$oUser['role']:'摄影师';
		}
		elseif ($oUser['usertype'] == 5)
		{
			$userRole = $oUser['role']?$oUser['role']:'化妆师';
		}
		elseif ($oUser['usertype'] == 6)
		{
			if ($oUser['role'])
			{
				$userRole = $oUser['role'];
			}
			else
			{
				if ($oUser['type'])
				{
					$oSysType = _get_config('type');
					$oSysType = $oSysType[6];
					$userRole = $oSysType[$oUser['type']];
				}
				else
				{
					$userRole = '艺人';
				}
			}
		}

		$result = array(
			'oUser' => $oUser,
			'list' => $list,
            'oCert' => $userCert,
			'userRole' => $userRole
		);
		if (isset($ins_user))
		{
			$result['ins_user'] = $ins_user;
		}
		$this->load->view('i/comment',$result);
	}

}